﻿using Autofac;
using Autofac.Core;
using Nop.Core.Configuration;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Web.Framework.Infrastructure.Extensions;
using Nop.Web.Services.Data;
using Nop.Web.Services.Domain;
using Nop.Web.Services.Easemob;
using Nop.Web.Services.Factories;
using Nop.Web.Services.Logging;
using Nop.Web.Services.Messages;
using Nop.Web.Services.Mob;
using Nop.Web.Services.Utils;
using System;
using System.Collections.Generic;
using System.Text;

namespace Nop.Web.Services.Infrastructure
{
    public class DependencyRegistrar : IDependencyRegistrar
    {
        public int Order => 9999;

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            builder.RegisterType<SafeLogger>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType<HPaySdkHelper>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType<HUCSdkHelper>().AsSelf().InstancePerLifetimeScope();

            const string contextName = "nop_object_context_nop_web_services";
            //data context
            builder.RegisterPluginDataContext<ServicesObjectContext>(contextName);

            //override required repository with our custom context
            builder.RegisterType<EfRepository<CustomerOrderCount>>().As<IRepository<CustomerOrderCount>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(contextName))
                .InstancePerLifetimeScope();


            builder.RegisterType<EfRepository<HPayWalletQueued>>().As<IRepository<HPayWalletQueued>>()
               .WithParameter(ResolvedParameter.ForNamed<IDbContext>(contextName))
               .InstancePerLifetimeScope(); 

            builder.RegisterType<MobPushHelper>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType<EasemobManager>().AsSelf().InstancePerLifetimeScope();

            builder.RegisterType<HUCFactory>().AsSelf().SingleInstance();

            builder.RegisterType<WorkflowMessageService>().As<Nop.Services.Messages.IWorkflowMessageService>().InstancePerLifetimeScope();
        }
    }
}
